package com.centanet.framework.glide;

import android.content.Context;

import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool;
import com.bumptech.glide.load.engine.cache.ExternalCacheDiskCacheFactory;
import com.bumptech.glide.load.engine.cache.LruResourceCache;
import com.bumptech.glide.load.engine.cache.MemorySizeCalculator;
import com.bumptech.glide.module.GlideModule;
import com.bumptech.glide.request.target.ViewTarget;
import com.centanet.centalib.R;

/**
 * glide全局配置，AndroidManifest.xml中添加如下配置&#60meta-data
 * android:name="com.centanet.framework.glide.GlobalGlideModule"
 * android:value="GlideModule" /&#62<p>
 * 初始化SD卡存储上限：100M；
 * 内存上限：2M
 */
public class GlobalGlideModule implements GlideModule {

    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
        MemorySizeCalculator memorySizeCalculator = new MemorySizeCalculator(context);
        builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, 100 * 1024 * 1024));
        builder.setMemoryCache(new LruResourceCache(memorySizeCalculator.getMemoryCacheSize() * 10 / 100));
        builder.setBitmapPool(new LruBitmapPool(memorySizeCalculator.getBitmapPoolSize() * 10 / 100));
        ViewTarget.setTagId(R.id.id_glide_tag);
    }

    @Override
    public void registerComponents(Context context, Glide glide) {

    }
}
